package com.ruoyi.psi.quality.report.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.psi.quality.report.domain.InspectReportCond;
import com.ruoyi.psi.quality.report.domain.InspectReportDomain;
import com.ruoyi.psi.quality.report.domain.InspectReportDto;
import com.ruoyi.psi.quality.report.service.IInspectReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 质检报告
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/psi/quality/report")
@Api(value = "质检报告模块", tags = "质检报告接口")
public class InspectReportController extends BaseController {
    @Autowired
    private IInspectReportService inspectReportService;

    /**
     * 获取质检报告列表
     * @param cond
     * @return
     */
    @ApiOperation(value = "获取质检报告列表",notes = "查询所有质检报告信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InspectReportCond cond){
        startPage();
        List<InspectReportDto> inspectReportList = inspectReportService.selectInspectReportList(cond);
        return getDataTable(inspectReportList);
    }


    /**
     * 导出质检报告
     * @param cond
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody InspectReportCond cond)
    {
        List<InspectReportDto> inspectReportList = inspectReportService.selectInspectReportList(cond);
        ExcelUtil<InspectReportDto> util = new ExcelUtil<>(InspectReportDto.class);
        return util.exportExcel(inspectReportList, "质检报告数据");
    }

    /**
     * 新增质检报告
     * @param inspectReport
     * @return
     */
    @ApiOperation(value = "新增质检报告",notes = "新增质检报告")
    @ApiImplicitParam(name = "inspectReport", value = "新增质检报告", dataType = "InspectReportDomain")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody InspectReportDomain inspectReport){
        return toAjax(inspectReportService.insertInspectReport(inspectReport));
    }

    /**
     * 修改质检报告
     * @param inspectReport
     * @return
     */
    @ApiOperation(value = "修改质检报告",notes = "修改质检报告")
    @ApiImplicitParam(name = "inspectReport", value = "修改质检报告", dataType = "InspectReportDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody InspectReportDomain inspectReport){
        return toAjax(inspectReportService.updateInspectReport(inspectReport));
    }

    /**
     * 删除质检报告
     * 仅修改删除标志位
     * @param inspectReport
     * @return
     */
    @ApiOperation(value = "删除质检报告",notes = "删除质检报告，仅修改删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody InspectReportDomain inspectReport)
    {

        return toAjax(inspectReportService.updateInspectReportDeleteFlag(inspectReport));
    }
}
